/**********************************
	A Class that Defines Allows 
	Dynamic Binding of keys to
	Actions.

	By Julian Williams
	Jan 22, 2010
***********************************/


#include <iostream>

#include <SFML/Graphics.hpp>

#include "input.h"
#include "app.h"

Dynamic_Input Binder;



//Assign a button to a specific function
//Neat little function, will allow for dynamic
//Binding of different keys to any action available
void Dynamic_Input::Assign_Button(std::string a, bool autoRepeat, InputType t, sf::Key::Code c)
{
	key.useAutoRepeat = autoRepeat;
    key.myInputType = t;
   // key.myEventType = e;
	key.myKeyCode = c;
	//key.myMouseButton = b;
    Keys[a] = key;
}//EoF



//for mouse
void Dynamic_Input::Assign_Button (std::string a, bool autoRepeat, InputType t, sf::Mouse::Button b)
{
	key.useAutoRepeat = autoRepeat;
    key.myInputType = t;
   // key.myEventType = e;
	//key.myKeyCode = c;
	key.myMouseButton = b;
    Keys[a] = key;
}//EoF


bool Dynamic_Input::Test_Action (std::string s)
{
	// Auto Repeat used
	if(Keys[s].useAutoRepeat)
	{
		//Key Event
		if((Keys[s].myInputType == KeyboardInput) && (App::getInstance().Get_RenderWindow()->GetInput().IsKeyDown(Keys[s].myKeyCode)))
		{
			//std::cout << "Key used\n";
			return (true);
		}

		//Mouse event
		if((Keys[s].myInputType == MouseInput) && App::getInstance().Get_RenderWindow()->GetInput().IsMouseButtonDown(Keys[s].myMouseButton))
		{
		//	std::cout << "Mouse \n";
			return (true);
		}
	}//use autorepeat
    return (false);
}//EoF
